﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace SoftballStats_BL
{
    public partial class AtBat
    {
#region Other Properties
        private Guid _ID;
        private Guid _PlayerGameID;
        private short _Inning;
        private short _NumberOfRBI;
        private bool _Run;
        private string _Outcome;
        private bool _Safe;

        public Guid ID
        {
            get
            {
                return _ID;
            }
            set
            {
                _ID = value;
            }
        }

        public Guid PlayerGameID
        {
            get
            {
                return _PlayerGameID;
            }
            set
            {
                _PlayerGameID = value;
            }
        }

        public short Inning
        {
            get
            {
                return _Inning;
            }
            set
            {
                _Inning = value;
            }
        }

        public short NumberOfRBI
        {
            get
            {
                return _NumberOfRBI;
            }
            set
            {
                _NumberOfRBI = value;
            }
        }

        public bool Run
        {
            get
            {
                return _Run;
            }
            set
            {
                _Run = value;
            }
        }

        public string Outcome
        {
            get
            {
                return _Outcome;
            }
            set
            {
                _Outcome = value;
            }
        }

        public bool Safe
        {
            get
            {
                return _Safe;
            }
            set
            {
                _Safe = value;
            }
        }
#endregion

#region Public Methods
        public static List<AtBat> GetAtBatsByPlayerGameID(Guid playerGameID)
        {
            List<SoftballStats_BL.AtBat> lstAtBats = new List<SoftballStats_BL.AtBat>();

            try
            {
                using (SqlConnection conn = new SqlConnection(Utility.GetConnectiongString()))
                {
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "spGetAtBatsByPlayerGameID";
                    cmd.Parameters.AddWithValue("@PlayerGameID", playerGameID);
                    conn.Open();
                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            AtBat thisAtBat = new AtBat();
                            thisAtBat.ID = Guid.Parse(dr["ID"].ToString());
                            thisAtBat.PlayerGameID = Guid.Parse(dr["PlayerGameID"].ToString());
                            thisAtBat.Inning = short.Parse(dr["Inning"].ToString());
                            thisAtBat.NumberOfRBI = short.Parse(dr["NumberOfRBI"].ToString());
                            thisAtBat.Run = bool.Parse(dr["Run"].ToString());
                            thisAtBat.Outcome = dr["Outcome"].ToString();
                            thisAtBat.Safe = bool.Parse(dr["Safe"].ToString());
                            lstAtBats.Add(thisAtBat);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Failed to get AtBats", ex);
            }

            return lstAtBats;
        }
#endregion
    }
}
